package com.example.origin.demo.demo.blockqueue;

import lombok.SneakyThrows;

import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.TimeUnit;

public class Storage3 {

    private LinkedBlockingQueue<Object> list = new LinkedBlockingQueue<Object>(10);

    @SneakyThrows
    public void put(Object obj) {
        list.put(obj);
        System.out.println("进入缓冲区");
    }

    @SneakyThrows
    public Object get() {
        Object obj = list.take();
        System.out.println("离开缓冲区");
        return obj;
    }

    public static void main(String[] args) throws InterruptedException {
        Storage2 storage1 = new Storage2();
        new Thread(()->{
            try {
                TimeUnit.SECONDS.sleep(2);
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
            storage1.get();
        }).start();

        for (int i = 0; i < 11; i++) {
            storage1.put(Integer.valueOf(1));
        }
    }

}